#include "stdafx.h"
#include "Math.h"

#include "Perlin.h"

float noiseLoop(float x, float y, float z, float minFreq, float maxFreq, float ampl)
{
	float value = 0;
	for (float f = minFreq; f < maxFreq; f *= 2)
		value += ampl * noise(x * f, y * f, z * f);
	return value;
}

float fractalSum(float x, float y, float z, float minFreq, float maxFreq)
{
	float value = 0;
	for (float f = minFreq; f < maxFreq; f *= 2)
		value += noise(x * f, y * f, z * f) / f;
	return value;
}

float turbulence(float x, float y, float z, float minFreq, float maxFreq)
{
	float value = 0;
	for (float f = minFreq; f < maxFreq; f *= 2)
		value += fabsf(noise(x * f, y * f, z * f)) / f;
	return value;
}

float smoothstep(float edge0, float edge1, float x)
{
    // Scale, bias and saturate x to 0..1 range
    x = saturate((x - edge0)/(edge1 - edge0)); 
    // Evaluate polynomial
    return x*x*(3 - 2*x);
}

XMVECTOR smoothInterp(XMVECTOR v1, XMVECTOR v2, float t)
{
	t = (std::min)((std::max)(t, 0.0f), 1.0f);
	//t = t*t*(3-2*t);
	XMVECTOR val = XMVectorAdd(
		v1,
		XMVectorMultiply(
			XMVectorReplicate(t),
			XMVectorSubtract(v2, v1)
	));
	return val;
}